package com.aracky.assess.controller;

import com.aracky.assess.model.entity.HrKpiUserPerformanceHeader;
import com.aracky.assess.service.HrKpiUserPerformanceHeaderService;
import com.aracky.assess.service.PushMsgService;
import com.aracky.common.util.ComUtil;
import com.aracky.common.vo.CommonResult;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author zengzhiping
 * @BelongsPackage com.aracky.system.controller
 * @CreateTime 2022-07-15
 * @Description
 */

@RestController
@RequestMapping("/wx")
@Api(tags = "企业微信相关接口接口")
public class WxController {


    @Autowired
    private PushMsgService pushMsgService;

    @Autowired
    private HrKpiUserPerformanceHeaderService hrKpiUserPerformanceHeaderService;


    @ApiOperationSupport(order = 1)
    @GetMapping("/sendScoreMsgToAssessor")
    @ApiOperation(value = "发送评分消息给考核人")
    public CommonResult sendScoreMsgToAssessor() {
        pushMsgService.pushScoreMsgToAssessor();
        return CommonResult.success("消息发送成功");
    }

    @ApiOperationSupport(order = 2)
    @GetMapping("/sendWriteMsgToEmployee")
    @ApiOperation(value = "发送填写消息给员工--可以指定发送人")
    public CommonResult sendWriteMsgToEmployee(List<String> idList) {
        List<HrKpiUserPerformanceHeader> headList = null;

        if (ComUtil.isNotNullList(idList)) {
            //查询所有未填写的数据
            headList = hrKpiUserPerformanceHeaderService.listByIds(idList);
        }

        if (ComUtil.isNullList(idList)) {
            //查询所有未填写的数据
            LambdaQueryWrapper<HrKpiUserPerformanceHeader> headerLambdaQueryWrapper =
                    Wrappers.<HrKpiUserPerformanceHeader>lambdaQuery()
                            .last("WHERE ( status IS NULL or status = '')");
            headList = hrKpiUserPerformanceHeaderService.list(headerLambdaQueryWrapper);
        }


        pushMsgService.pushWriteMsgToEmployee(headList);
        return CommonResult.success("消息发送成功");
    }

    @ApiOperationSupport(order = 3)
    @GetMapping("/sendCompleteMsgToEmployee")
    @ApiOperation(value = "发送评分完成消息给员工(评分完成)")
    public CommonResult sendCompleteMsgToEmployee(Long taskId, Long userId) {

        pushMsgService.pushCompleteMsgToEmployee(taskId, userId);
        return CommonResult.success("消息发送成功");
    }

    @ApiOperationSupport(order = 4)
    @GetMapping("/demo")
    @ApiOperation(value = "提醒员工填报")
    public CommonResult demo(){
        List<HrKpiUserPerformanceHeader> headList=new ArrayList<>();
        pushMsgService.pushWriteMsgToEmployee(headList);
        return CommonResult.success("成功");
    }


    @GetMapping("/redis")
    @ApiOperation(value = "发送redis消息")
    public CommonResult test(){
        pushMsgService.pushRedisMsg();
        return CommonResult.success("成功");
    }
}
